<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="assets/mui/css/mui.min.css">
    <link rel="stylesheet" href="assets/fontAwesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/login.css">
      <script src="assets/zepto/zepto.min.js"></script>
    <script src="assets/mui/js/mui.js"></script>
    <script src="./js/common.js"></script>
    <!-- <script src='js/search-result.js'></script> -->

</head>

<body>
    <header class="mui-bar mui-bar-nav header">
        <h1 class="mui-title">登录</h1>
    

    </header>
    <nav class="mui-bar mui-bar-tab footer">
        <a class="mui-tab-item mui-active" href="index.html">
            <span class="mui-icon mui-icon-home"></span>
            <span class="mui-tab-label">首页</span>
        </a>
        <a class="mui-tab-item" href="category.html">
            <span class="mui-icon mui-icon-bars"></span>
            <span class="mui-tab-label">分类</span>
        </a>
        <a class="mui-tab-item" href="cart.html">
            <span class="mui-icon fa fa-shopping-cart"></span>
            <span class="mui-tab-label">购物车</span>
        </a>
        <a class="mui-tab-item" href="user.html">
            <span class="mui-icon mui-icon-person"></span>
            <span class="mui-tab-label">会员中心</span>
        </a>
    </nav>
    <div class="mui-content">
            <form class="mui-input-group">
                <div class="mui-input-row">
                    <label>用户名</label>
                    <input type="text" name="username" class="mui-input-clear" placeholder="请输入用户名">
                </div>
                <div class="mui-input-row">
                    <label>密码</label>
                    <input type="password" name="pwd" class="mui-input-password" placeholder="请输入密码">
                </div>
                <div class="mui-button-row">
                    <button type="button" class=" reg mui-btn mui-btn-primary">登录</button>
                </div>
            </form>
            <a href="login.html" class="mui-pull-right login">免费注册</a>
        </div>
    
</body>
<script>
    $('.reg').on('tap',function(){
        var username = $('input[name="username"]').val();
        
        var psw = $('input[name="pwd"]').val();
        
        if (username == ''){

            mui.toast('请输入用户名');

            return;

        }

        if (psw == ''){
            
            mui.toast('请输入密码');

            return;

        }
        
        $.ajax({
            url:'/user/login',
            type:'post',
            beforeSend: function () {

                $('reg').html('正在登陆中.....')

            },
            data:{
                username:username,
                password:psw,
            },
            success:function(res){

                if (res.success) {

                    $('reg').html('登陆成功。。。')

                    setTimeout(() => {

                        location.href='user.html'

                    },1000);

                }else if (res.error) {

                    mui.toast(res.message)

                }
            }
        })
    })
</script>
</html>